package logic

import (
	"context"
	"errors"
	"product-payment/models/mysql"

	"product-payment/prorpc/internal/svc"
	"product-payment/prorpc/prorpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type DrinkAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewDrinkAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DrinkAddLogic {
	return &DrinkAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *DrinkAddLogic) DrinkAdd(in *prorpc.DrinkAddRequest) (*prorpc.DrinkAddResponse, error) {
	// todo: add your logic here and delete this line
	var drink mysql.Drink
	mysql.DB.Debug().Where("id = 1", drink.ID).Find(&drink)

	if drink.ID == 0 {
		return nil, errors.New("当前饮料不存在")
	}
	drink = mysql.Drink{
		DrinkName:  in.DrinkName,
		DrinkPrice: float64(in.Price),
		We:         in.We,
		Info:       in.Info,
		DrinkNum:   int(in.DrinkNum),
		Image:      in.Image,
	}
	mysql.DB.Debug().Create(&drink)

	return &prorpc.DrinkAddResponse{
		DrinkId: int64(drink.ID),
	}, nil
}
